package backend;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class SqlConnection {
	
	public static SqlConnection getInstance() {
		if( instance == null ) {
			instance = new SqlConnection();
		}
		return instance;
	}
	
	public Connection getConnection() throws SQLException {
		Connection conn = null;
		Properties connectionProps = new Properties();
		connectionProps.put("user", this.userName);
		connectionProps.put("password", this.password);

		if (this.dbms.equals("mysql")) {
		  conn = DriverManager.
			getConnection("jdbc:" + this.dbms + "://" + this.serverName +
						  ":" + this.portNumber + "/" + this.dbName, connectionProps);
		} else if (this.dbms.equals("derby")) {
		  conn = DriverManager.
			getConnection("jdbc:" + this.dbms + ":" + this.dbName + ";create=true", connectionProps);
		}
		return conn;
	  }
	
	private SqlConnection() {
		userName   = "mywormho_admin";
		password   = "nw23sd";
		dbms       = "mysql";
		dbName     = "mywormho_international";
		serverName = "184.22.145.67"; 
//		userName   = "root";
//		password   = "";
//		dbms       = "mysql";
//		dbName     = "mywormho_international";
//		serverName = "localhost"; 
		portNumber = 3306;
	}
	
	private static SqlConnection instance = null;
	private String userName;
	private String password;
	private String dbms;
	private String dbName;
	private String serverName;
	private int    portNumber;
}
